package org.filecollector.filecontroller;

import org.filecollector.filecontroller.basicsfilecontroller.BasicsFileControllerDependencies;
import org.filecollector.filecontroller.basicsfilecontroller.BasicsFileControllerFactory;
import org.filecollector.filecontroller.virtualcatalogue.groupname.GroupName;

import java.util.List;

public abstract class FileControllerFactory {

    /**
     * Constructs FileController by list of directories
     * @param name file name
     * @param dirs names of inner catalogues
     * @param doIfTroubles function that will be run if something go wrong
     * @param dependencies dependencies of File Controller
     * @return FileController or null if {@code doIfTroubles} doesn't throw anything
     */
    public static FileController constructByList(
            GroupName name,
            List<String> dirs,
            Runnable doIfTroubles,
            BasicsFileControllerDependencies dependencies
    ) {
        var ret = BasicsFileControllerFactory.createByListOfFiles(name, dirs, dependencies);
        if (ret.isEmpty()) {
            doIfTroubles.run();
            return null;
        }
        return ret.get();
    }
}
